package com.zheng.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: ztl
 * @date: 2025/04/09 22:39
 * @desc:
 */

@RestController
public class MessageProductorController {

    @Autowired
    private Source source;

    /**
     * 消息发送者
     * @param msg
     * @return
     */
    @RequestMapping("/send/{msg}")
    public String send(@PathVariable String msg){
        MessageBuilder<String> stringMessageBuilder = MessageBuilder.withPayload(msg);
        source.output().send(stringMessageBuilder.build());
        System.out.println("发送了： "+msg);
        return "消息发送成功："+msg;
    }
}
